package com.bookmanager.www.controller.rabbitmq;

import com.bookmanager.www.common.utils.StringUtils;
import com.bookmanager.www.mapper.FlBookorderMapper;
import org.checkerframework.checker.units.qual.A;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 风离
 * @Date: 2021/11/17/12:30
 * @Description:
 */
@Component //死信队列
public class OrderDlxConsumer {

    @Resource
    FlBookorderMapper flBookorderMapper;


    /**
     * 监听我们的死信队列
     */
    @RabbitListener(queues = "mayikt_order_dlx_queue")
    public void orderConsumer(String orderId) {
        System.out.println("死信队列获取消息:" + orderId);
        if (StringUtils.isEmpty(orderId)) {
            return;
        }
        //根据id查询
//        OrderEntity orderEntity = orderMapper.getOrder(orderId);
//        if (null == orderEntity) {
//            return;
//        }
        //获取状态
        Integer orderStatus= flBookorderMapper.getStatusByOrderId(orderId);
        //判断未支付 , 关闭订单
        if(0==orderStatus){
            //关闭订单
            flBookorderMapper.changeStatusByOrderId(orderId,-1);
            //库存返还
        }
    }
}